/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.camachosanchez.gui;

import com.camachosanchez.bean.ConfiguracionBajaNeumatico;
import com.camachosanchez.bean.EstadosMedicion;
import com.camachosanchez.controler.jpa.ConfiguracionBajaNeumaticoJpaController;
import com.camachosanchez.controler.jpa.EstadosMedicionJpaController;
import com.camachosanchez.util.EstadosJDialog;
import com.camachosanchez.util.GUIUtil;
import java.awt.Color;
import java.awt.event.KeyEvent;
import java.math.BigDecimal;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JColorChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author ZULLY
 */
public class EditorConfiguracionBaja extends javax.swing.JDialog {

    public EstadosJDialog.EstadoJDialog Estado;
    private MaestroConfiguracionBaja buscador;
    private int fila;
    private ConfiguracionBajaNeumatico configuracion;
    
    /**
     * Creates new form EditorConfiguracionBaja
     */
    public EditorConfiguracionBaja(MaestroConfiguracionBaja buscador, java.awt.Frame parent, boolean modal, ConfiguracionBajaNeumatico configuracion, int fila) {
        super(parent, modal);
        initComponents();
        this.setLocationRelativeTo(null);
        GUIUtil.addEscapeKey(this);
        EstadosMedicionJpaController dao_estadosMedicion = new EstadosMedicionJpaController(null);
        List<EstadosMedicion> estadosMedicion = dao_estadosMedicion.findEstadosMedicionEntities();
        cmbEstadoMedicion.setModel(new DefaultComboBoxModel(estadosMedicion.toArray()));
        
        this.buscador = buscador;
        this.fila = fila;
        if (configuracion != null) {
            this.CargarDatosConfiguracion(configuracion);
            this.configuracion = configuracion;
        }
        txtDescripcion.requestFocusInWindow();
        
    }

    private void CargarDatosConfiguracion(ConfiguracionBajaNeumatico configuracion) {
        txtDescripcion.setText(configuracion.getDescripcion());
        txtColor.setText("" + configuracion.getColor());
        txtColor.setBackground(new Color(configuracion.getColor()));
        txtValorIni.setText("" + configuracion.getValorInicial());
        txtValorFin.setText("" + configuracion.getValorFinal());
        if(configuracion.getNroReencauches() != null){
            chkReencauches.setSelected(true);
            spnReencauches.setEnabled(true);
            spnReencauches.setValue(configuracion.getNroReencauches());
        } else{
            chkReencauches.setSelected(false);
            spnReencauches.setEnabled(false);
        }
        if(configuracion.getIdEstadoMedicion() != null){
            chkEstado.setSelected(true);
            cmbEstadoMedicion.setEnabled(true);
            cmbEstadoMedicion.setSelectedItem(configuracion.getIdEstadoMedicion());
        } else {
            chkEstado.setSelected(false);
            cmbEstadoMedicion.setEnabled(false);
        }
    }
    
    public EstadosJDialog.EstadoJDialog getEstado() {
        return Estado;
    }

    public void setEstado(EstadosJDialog.EstadoJDialog Estado) {
        switch (Estado) {
            case NUEVO:
                btnEliminar.setVisible(false);
                break;
            case MODIFICAR:
                btnEliminar.setVisible(true);
                break;
        }
        this.Estado = Estado;
    }
    
    private boolean ValidarDatos() {
        if (txtDescripcion.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Se requiere una descripción para la configuración.", "Datos incompletos", JOptionPane.WARNING_MESSAGE);
            txtDescripcion.requestFocusInWindow();
            return false;
        }
        if (txtColor.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Se requiere un color para la configuración.", "Datos incompletos", JOptionPane.WARNING_MESSAGE);
            txtColor.requestFocusInWindow();
            return false;
        }
        if (txtValorIni.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Se requiere un valor inicial para la configuración.", "Datos incompletos", JOptionPane.WARNING_MESSAGE);
            txtValorIni.requestFocusInWindow();
            return false;
        }
        double valor1, valor2;
        try {
            valor1 = Double.parseDouble(txtValorIni.getText());
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(this, "El valor ingresado para el valor inicial debe ser un número válido.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
            txtValorIni.requestFocusInWindow();
            return false;
        }
        if (txtValorFin.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Se requiere un valor final para la configuración.", "Datos incompletos", JOptionPane.WARNING_MESSAGE);
            txtValorFin.requestFocusInWindow();
            return false;
        }
        try {
            valor2 = Double.parseDouble(txtValorFin.getText());
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(this, "El valor ingresado para el valor final debe ser un número válido.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
            txtValorFin.requestFocusInWindow();
            return false;
        }
        if (valor1 >= valor2) {
            JOptionPane.showMessageDialog(this, "El valor inicial no puede ser mayor o igual que el valor final.", "Datos incompletos", JOptionPane.WARNING_MESSAGE);
            txtValorIni.requestFocusInWindow();
            return false;
        }
        return true;
    }
    
    private void GuardarDatos() {
        switch (this.Estado) {
            case NUEVO:
                RegistrarConfiguracion(LeerDatosConfiguracion());
                break;
            case MODIFICAR:
                ModificarConfiguracion(LeerDatosConfiguracion());
                break;
            case ELIMINAR:
                break;
            default:
                break;
        }
    }
    
    private ConfiguracionBajaNeumatico LeerDatosConfiguracion() {
        ConfiguracionBajaNeumatico c = new ConfiguracionBajaNeumatico();
        c.setDescripcion(txtDescripcion.getText().trim());
        c.setColor(Integer.parseInt(txtColor.getText()));
        c.setValorInicial(new BigDecimal(txtValorIni.getText()));
        c.setValorFinal(new BigDecimal(txtValorFin.getText()));
        if(chkReencauches.isSelected()){
            c.setNroReencauches(new Short(this.spnReencauches.getValue().toString()));
        } else {
            c.setNroReencauches(null);
        }
        if(chkEstado.isSelected()){
            c.setIdEstadoMedicion((EstadosMedicion)cmbEstadoMedicion.getSelectedItem());
        } else {
            c.setIdEstadoMedicion(null);
        }
        return c;
    }
    
    private void RegistrarConfiguracion(ConfiguracionBajaNeumatico configuracion) {
        ConfiguracionBajaNeumaticoJpaController dao_conf = new ConfiguracionBajaNeumaticoJpaController(null);
        configuracion.setEstado(true);
        dao_conf.create(configuracion);
        JOptionPane.showMessageDialog(this, "La configuración de baja de neumático ha sido guardada correctamente.", "Operación finalizada", JOptionPane.INFORMATION_MESSAGE);
        buscador.llenarConfiguracionesBaja();
        this.dispose();
    }

    private void ModificarConfiguracion(ConfiguracionBajaNeumatico configuracion) {
        ConfiguracionBajaNeumaticoJpaController dao_conf = new ConfiguracionBajaNeumaticoJpaController(null);
        try {
            configuracion.setEstado(true);
            configuracion.setId(this.configuracion.getId());
            dao_conf.edit(configuracion);
            JOptionPane.showMessageDialog(this, "Los datos del insumo de despinche han sido actualizados correctamente.", "Operación finalizada", JOptionPane.INFORMATION_MESSAGE);
            buscador.llenarConfiguracionesBaja();
            dispose();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(Principal.getInstance(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        txtDescripcion = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtColor = new javax.swing.JTextField();
        btnSeleccionarColor = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtValorIni = new javax.swing.JTextField();
        txtValorFin = new javax.swing.JTextField();
        chkReencauches = new javax.swing.JCheckBox();
        spnReencauches = new javax.swing.JSpinner();
        chkEstado = new javax.swing.JCheckBox();
        cmbEstadoMedicion = new javax.swing.JComboBox();
        pnlToolBar = new javax.swing.JPanel();
        btnGuardar = new javax.swing.JButton();
        btnEliminar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(".:: Configuración de Baja de Neumático ::.");
        setResizable(false);

        txtDescripcion.setNextFocusableComponent(btnSeleccionarColor);
        txtDescripcion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtDescripcionKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDescripcionKeyTyped(evt);
            }
        });

        jLabel1.setLabelFor(txtDescripcion);
        jLabel1.setText("<html>Descripción: <font color='red'>(*)</font></html>");

        jLabel2.setLabelFor(txtColor);
        jLabel2.setText("Color:");

        txtColor.setEnabled(false);

        btnSeleccionarColor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/color_picker.png"))); // NOI18N
        btnSeleccionarColor.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnSeleccionarColor.setBorderPainted(false);
        btnSeleccionarColor.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnSeleccionarColor.setNextFocusableComponent(txtValorIni);
        btnSeleccionarColor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSeleccionarColorActionPerformed(evt);
            }
        });

        jLabel3.setLabelFor(txtValorIni);
        jLabel3.setText("Valor Inicial:");

        jLabel4.setLabelFor(txtValorFin);
        jLabel4.setText("Valor Final:");

        txtValorIni.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtValorIniKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtValorIniKeyTyped(evt);
            }
        });

        txtValorFin.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtValorFinKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtValorFinKeyTyped(evt);
            }
        });

        chkReencauches.setText("N° Reencauches");
        chkReencauches.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chkReencauchesActionPerformed(evt);
            }
        });

        spnReencauches.setEnabled(false);
        spnReencauches.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                spnReencauchesKeyPressed(evt);
            }
        });

        chkEstado.setText("Estado:");
        chkEstado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chkEstadoActionPerformed(evt);
            }
        });

        cmbEstadoMedicion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbEstadoMedicion.setEnabled(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtValorIni, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txtValorFin, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(txtDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel2)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(txtColor, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(btnSeleccionarColor, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(chkReencauches)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(spnReencauches, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(chkEstado)
                                .addGap(18, 18, 18)
                                .addComponent(cmbEstadoMedicion, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(158, 158, 158)))))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2, jLabel3, jLabel4, txtColor, txtValorFin, txtValorIni});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(txtColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnSeleccionarColor))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(txtValorFin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtValorIni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(chkReencauches)
                    .addComponent(spnReencauches, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(chkEstado)
                    .addComponent(cmbEstadoMedicion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(11, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        pnlToolBar.setBackground(new java.awt.Color(255, 255, 255));
        pnlToolBar.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/24_save.png"))); // NOI18N
        btnGuardar.setToolTipText("Guardar");
        btnGuardar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnGuardar.setFocusable(false);
        btnGuardar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnGuardar.setMaximumSize(new java.awt.Dimension(22, 22));
        btnGuardar.setMinimumSize(new java.awt.Dimension(22, 22));
        btnGuardar.setPreferredSize(new java.awt.Dimension(22, 22));
        btnGuardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });
        pnlToolBar.add(btnGuardar);

        btnEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/24_delete.png"))); // NOI18N
        btnEliminar.setToolTipText("Eliminar");
        btnEliminar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnEliminar.setFocusable(false);
        btnEliminar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnEliminar.setMaximumSize(new java.awt.Dimension(22, 22));
        btnEliminar.setMinimumSize(new java.awt.Dimension(22, 22));
        btnEliminar.setPreferredSize(new java.awt.Dimension(22, 22));
        btnEliminar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });
        pnlToolBar.add(btnEliminar);

        getContentPane().add(pnlToolBar, java.awt.BorderLayout.PAGE_START);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        // TODO add your handling code here:
        if (ValidarDatos()) {
            GuardarDatos();
        }
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void btnSeleccionarColorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSeleccionarColorActionPerformed
        // TODO add your handling code here:
        Color colorInicial = txtColor.getBackground();
        Color background = JColorChooser.showDialog(null, "Color de Baja de Neumático", colorInicial);
        if (background != null) {
            txtColor.setBackground(background);
            txtColor.setText("" + background.getRGB());
            txtValorIni.requestFocusInWindow();
        }
    }//GEN-LAST:event_btnSeleccionarColorActionPerformed

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed
        // TODO add your handling code here:
        if (JOptionPane.showConfirmDialog(null, "¿Está seguro que desea eliminar esta configuración de baja?", "Confirmación", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            ConfiguracionBajaNeumaticoJpaController dao_conf = new ConfiguracionBajaNeumaticoJpaController(null);
            try {
                configuracion.setEstado(false);
                configuracion.setId(this.configuracion.getId());
                dao_conf.edit(configuracion);
                JOptionPane.showMessageDialog(this, "Los datos de la configuración de baja de neumático han sido actualizados correctamente.", "Operación finalizada", JOptionPane.INFORMATION_MESSAGE);
                buscador.llenarConfiguracionesBaja();
                dispose();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(Principal.getInstance(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_btnEliminarActionPerformed

    private void txtDescripcionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDescripcionKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            btnSeleccionarColor.requestFocusInWindow();
        }
    }//GEN-LAST:event_txtDescripcionKeyPressed

    private void txtDescripcionKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDescripcionKeyTyped
        // TODO add your handling code here:
        String caracteres = txtDescripcion.getText();
        if (caracteres.length() >= 40) {
            evt.consume();
        }
    }//GEN-LAST:event_txtDescripcionKeyTyped

    private void txtValorIniKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtValorIniKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            txtValorFin.requestFocusInWindow();
        }
    }//GEN-LAST:event_txtValorIniKeyPressed

    private void txtValorFinKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtValorFinKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            btnGuardar.requestFocusInWindow();
        }
    }//GEN-LAST:event_txtValorFinKeyPressed

    private void txtValorIniKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtValorIniKeyTyped
        // TODO add your handling code here:
        String caracteres = txtValorIni.getText();
        if (caracteres.length() >= 6) {
            evt.consume();
        }
    }//GEN-LAST:event_txtValorIniKeyTyped

    private void txtValorFinKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtValorFinKeyTyped
        // TODO add your handling code here:
        String caracteres = txtValorFin.getText();
        if (caracteres.length() >= 6) {
            evt.consume();
        }
    }//GEN-LAST:event_txtValorFinKeyTyped

    private void spnReencauchesKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_spnReencauchesKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            txtValorIni.requestFocusInWindow();
        }
    }//GEN-LAST:event_spnReencauchesKeyPressed

    private void chkEstadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkEstadoActionPerformed
        // TODO add your handling code here:
        cmbEstadoMedicion.setEnabled(chkEstado.isSelected());
    }//GEN-LAST:event_chkEstadoActionPerformed

    private void chkReencauchesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkReencauchesActionPerformed
        // TODO add your handling code here:
        spnReencauches.setEnabled(chkReencauches.isSelected());
    }//GEN-LAST:event_chkReencauchesActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnSeleccionarColor;
    private javax.swing.JCheckBox chkEstado;
    private javax.swing.JCheckBox chkReencauches;
    private javax.swing.JComboBox cmbEstadoMedicion;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel pnlToolBar;
    private javax.swing.JSpinner spnReencauches;
    private javax.swing.JTextField txtColor;
    private javax.swing.JTextField txtDescripcion;
    private javax.swing.JTextField txtValorFin;
    private javax.swing.JTextField txtValorIni;
    // End of variables declaration//GEN-END:variables
}
